var t,
  n = require("../../res/www.a9a.cn.js"),
  a = getApp();
Page({
  data: {
    www_zeai_cn: null,
    div_sign_box: !1,
    hasDraw: !1,
    nTitle: "我的承诺书",
  },
  onLoad: function () {
    var o = this;
    a.get_config("_ZEAI").then(function (t) {
      o.setData({ color: t.color, rgbcolor: n.c16_rgb(t.color) });
    }),
      wx.setNavigationBarTitle({ title: o.data.nTitle }),
      a.chklogin().then(function (i) {
        i
          ? ((t = wx.getStorageSync("COOK_U")),
            wx.showLoading({ title: "玩命加载中", mask: !0 }),
            a.ajax({
              url: "my_sign.php",
              data: { submitok: "init", openid: t.openid },
              success: function (t) {
                n.empty(t.sign_pdf_path) ||
                  wx.showModal({
                    content: "可在承诺书上面按住不放保存图片",
                    confirmColor: o.data.color,
                    confirmText: "朕知道了",
                    showCancel: !1,
                    success: function (t) {},
                  }),
                  1 == t.flag
                    ? o.setData({
                        nTitle: t.nTitle,
                        sign_png_path: t.sign_png_path,
                        sign_pdf_path: t.sign_pdf_path,
                        sign_pdf_flag_str: t.sign_pdf_flag_str,
                      })
                    : "noreg" == t.flag
                    ? wx.switchTab({ url: "../my/my" })
                    : ((t.this = o), (t.url = "no"), n.sorry(t)),
                  wx.hideLoading();
              },
            }))
          : wx.showModal({
              content: "亲~~~请先登录完善资料再来申请哦",
              confirmColor: o.data.color,
              confirmText: "朕知道了",
              showCancel: !1,
              success: function (t) {
                wx.switchTab({ url: "../my/my" });
              },
            });
      });
  },
  singFn: function () {
    if (n.empty(this.data.sign_pdf_path)) {
      var t = wx.createCanvasContext("a9a_cn___Canvas");
      t.setStrokeStyle("#000000"),
        t.setLineWidth(5),
        this.setData({ www_zeai_cn: t }),
        this.setData({ div_sign_box: !0 });
    } else
      wx.showModal({
        content: "可在承诺书上面按住不放保存图片",
        confirmColor: this.data.color,
        confirmText: "朕知道了",
        showCancel: !1,
        success: function (t) {},
      });
  },
  signDownFn: function () {
    n.empty(this.data.sign_pdf_path)
      ? this.setData({ div_sign_box: !0 })
      : wx.downloadFile({
          url: this.data.sign_pdf_path,
          success: function (t) {
            200 === t.statusCode &&
              wx.openDocument({
                filePath: t.tempFilePath,
                fileType: "pdf",
                showMenu: !0,
                success: function (t) {},
                fail: function (t) {
                  wx.showToast({ icon: "none", title: "打开文件失败" });
                },
              });
          },
        });
  },
  div_sign_form_closeFn: function () {
    this.setData({ div_sign_box: !1 });
  },
  touchstartFn: function (t) {
    var n = this.data.www_zeai_cn;
    n.moveTo(t.touches[0].x, t.touches[0].y),
      this.setData({ www_zeai_cn: n, hasDraw: !0 });
  },
  touchmoveFn: function (t) {
    var n = t.touches[0].x,
      a = t.touches[0].y,
      o = this.data.www_zeai_cn;
    o.setLineWidth(5),
      o.lineTo(n, a),
      o.stroke(),
      o.setLineCap("round"),
      o.draw(!0),
      o.moveTo(n, a);
  },
  signreset: function () {
    this.data.www_zeai_cn.draw(), this.setData({ hasDraw: !1, src: null });
  },
  signok: function () {
    var o = this;
    o.data.hasDraw
      ? o.data.www_zeai_cn.draw(
          !0,
          wx.canvasToTempFilePath({
            canvasId: "a9a_cn___Canvas",
            success: function (i) {
              wx.showLoading({ title: "正成生成签名", mask: !0 }),
                wx.uploadFile({
                  url: a.WWW + "/api/wxxcx/my_sign.php",
                  filePath: i.tempFilePath,
                  name: "pic",
                  formData: { submitok: "save", openid: t.openid },
                  success: function (t) {
                    (t = n.jsoneval(t.data)),
                      wx.hideLoading(),
                      1 == t.flag
                        ? (o.setData({ div_sign_box: !1 }),
                          wx.showToast({
                            title: "保存成功！",
                            icon: "none",
                            mask: !0,
                          }),
                          o.onLoad())
                        : wx.showModal({
                            content: t.msg,
                            confirmColor: o.data.color,
                            confirmText: "朕知道了",
                            showCancel: !1,
                            success: function (t) {},
                          });
                  },
                });
            },
          })
        )
      : wx.showToast({ title: "请手写自己的真实姓名", icon: "none", mask: !0 });
  },
  mask_closeFn: function (t) {
    wx.navigateBack();
  },
  certFn: function () {
    wx.navigateTo({ url: "../my/cert" });
  },
});
